﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Entity;
using System.Data.SqlClient;

namespace LotteryVote.Data
{
    public class LotterySpecieDataAccess : DataBase
    {
        public LotterySpecies GetSpecie(int specieId)
        {
            string sql = string.Format(@"SELECT * FROM {0} WHERE {1}=@{1}", LotterySpecies.TABLENAME, LotterySpecies.SPECIEID);
            return base.ExecuteEntity<LotterySpecies>(sql, new SqlParameter(LotterySpecies.SPECIEID, specieId));
        }
        /// <summary>
        /// 获取用户支持的彩票种类.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns></returns>
        public IList<LotterySpecies> GetSpeciesByUser(User user)
        {
            string sql = string.Format(@"select ls.* from {0} ls
join {1} uc on uc.{2}=ls.{3}
where uc.{4}=@{4}", LotterySpecies.TABLENAME, UserCommission.TABLENAME, LotterySpecies.SPECIEID, UserCommission.SPECIEID, UserCommission.USERID);
            return base.ExecuteList<LotterySpecies>(sql, new SqlParameter(UserCommission.USERID, user.UserId));
        }
        public IList<LotterySpecies> GetAllSpecies()
        {
            string sql = string.Format(@"SELECT * FROM {0}", LotterySpecies.TABLENAME);
            return base.ExecuteList<LotterySpecies>(sql);
        }
    }
}
